// 这里应该是注册全局组件
//属性列表  硬件属性
Vue.component('select-property-hide', {
    data: function () {
        return {
            reallyProValue: null,
            reallyProOption: null,
        }
    },
    // props: ["message"],
    template: '<el-select    @change="changFunction"   v-model="reallyProValue" >\n' +
    '                    <el-option v-for="item in reallyProOption" :key="item.id" :label="item.proRemark"\n' +
    '                               :value="item.id">\n' +
    '                    </el-option>\n' +
    '                </el-select>',
    created: function () {
        //获取后台数据
        var language = localStorage.getItem("language");  //获取名称为“key”的值
        this.$http.get('../readMap/findHisDataType.do?languageType='+language+'&type=1', {emulateJSON: true}).then(function (res) {
            // console.log(res.data[0].proNamech);
            this.reallyProValue=res.data[0].id;
            this.$emit('send-property-hide-first', res.data[0]);
            this.reallyProOption = res.data;
        });
    },methods:{
        changFunction(id){//change事件
            let entity = {};
            entity = this.reallyProOption.find((item)=>{
                return item.id === id;  //筛选出匹配数据，这里的value是你遍历数组每一项的value，如果没有对后台返回的数据做处理，一般为id
            });
            //返回一个值
            this.$emit('send-property-hide',  entity);
        }
    }
});

//模拟属性
Vue.component('select-property-simulate', {
    data: function () {
        return {
            siteTypeOption: "",       //类别
            siteTypeOptionValue: "",    //类别选项
        }
    },
    // props: ["message"],
    template: '  <el-select @change="changFunction"   v-model="siteTypeOptionValue" placeholder="请选择类型"  value-key="id"  class="topSelectRight"\n' +
    '                           style="width: 150px">\n' +
    '                    <el-option v-for="item in siteTypeOption" :key="item.id" :label="item.proRemark"\n' +
    '                               :value="item">\n' +
    '                    </el-option>\n' +
    '                </el-select>',
    created: function () {
        var language = localStorage.getItem("language");  //获取名称为“key”的值
        //获取后台数据
        this.$http.get('/readMap/findHisDataType.do?type=0&languageType='+language, {emulateJSON: true}).then(function (res) {
            // console.log(res2);
            this.siteTypeOption = res.data;
            //初始返回第一个值
            // console.log(res.data[0].id);
            this.siteTypeOptionValue=res.data[0];
            this.$emit('send-property-simulate',  res.data[0].id);
            this.$emit('send-property-simulate-entity', res.data[0]);
        });
    },methods:{
        changFunction(){//change事件
             //返回一个值
            this.$emit('send-property-simulate',  this.siteTypeOptionValue.id);
            //返回一个实体
            this.$emit('send-property-simulate-entity', this.siteTypeOptionValue);
        }
    }
});
// his文件
Vue.component('select-file-his', {
    data: function () {
        return {
            fileOptionValue: "",         //文件
            fileOption: null,       //文件选项
        }
    },
    props: ['onemonth'],
    template: ' <el-select @change="changFunction"   v-model="fileOptionValue"    value-key="id"  class="topSelectRight">\n' +
    '                    <el-option v-for="item in fileOption" :key="item.id" :label="item.fileName"\n' +
    '                               :value="item">\n' +
    '                    </el-option>\n' +
    '                </el-select>\n',
    created: function () {
        //获取后台数据
        this.$http.get('/readMap/findFileType.do?type=his', {emulateJSON: true}).then(function (res) {
            console.log(res.data);
            //默认显示第一个
            if(this.onemonth == 1){
                //删除第一个元素
                res.data.shift();
            }
            this.fileOption = res.data;
            this.fileOptionValue=res.data[0];
            this.$emit('send-file-his',  res.data[0].id);
            this.$emit('send-file-his-entity',  res.data[0]);

        });

    },methods:{
        changFunction(){//change事件

            this.$emit('send-file-his',  this.fileOptionValue.id);
            this.$emit('send-file-his-entity',  this.fileOptionValue);
        }
    }
});
Vue.component('select-file-map', {
    data: function () {
        return {
            fileOptionValue: "",         //文件
            fileOption: null,       //文件选项
        }
    },
    // props: ["message"],
    template: ' <el-select @change="changFunction"   v-model="fileOptionValue" placeholder="map"  value-key="id"  class="topSelectRight">\n' +
    '                    <el-option v-for="item in fileOption" :key="item.id" :label="item.fileName"\n' +
    '                               :value="item">\n' +
    '                    </el-option>\n' +
    '                </el-select>\n',
    created: function () {
        //获取后台数据
        this.$http.get('/readMap/findFileType.do?type=map', {emulateJSON: true}).then(function (res) {
            this.fileOption = res.data;
        });
    },methods:{
        changFunction(){//change事件
            this.$emit('send-file-his',  this.fileOptionValue.id);
            this.$emit('send-file-his-entity',  this.fileOptionValue);
        }
    }
});


//站点 DM1 ---  DM5
Vue.component('select-site', {
    data: function () {
        return {
            siteOption: ["DM1", "DM2", "DM3", "DM4", "DM5"],        //观测点
            siteOptionValue: "DM2",     //观测点数据
        }
    },
    // props: ["message"],
    template: "    <el-select  @change=\"$emit('send-site',  siteOptionValue)\"   v-model=\"siteOptionValue\" placeholder=\"请选择站点\" class=\"topSelectRight\" style=\"width: 150px\" >\n" +
    "                    <el-option v-for=\"item in siteOption\" :key=\"item\" :label=\"item\"\n" +
    "                               :value=\"item\" >\n" +
    "                    </el-option>\n" +
    "                </el-select>",
});

// 层数
Vue.component('select-tier', {
    data: function () {
        return {
            tierOption: ["1", "2", "3", "4", "5"],// 层数
            tierOptionValue: "1",        //层数选项
        }
    },
    template: "<el-select @change=\"$emit('send-tier',  tierOptionValue)\"  v-model=\"tierOptionValue\" placeholder=\"请选择层数\" class=\"topSelectRight\" style=\"width: 150px\"  >\n" +
    "                    <el-option v-for=\"item in tierOption\" :key=\"item\" :label=\"item\"\n" +
    "                               :value=\"item\">\n" +
    "                    </el-option>\n" +
    "                </el-select>",
});

//数据库获取站点
Vue.component('select-site-sql', {
    data: function () {
        return {
            siteOption: null,        //观测点
            siteOptionValue: null,     //观测点数据
        }
    },
    // props: ["message"],
    template: '<el-select    @change="changFunction"   v-model="siteOptionValue" >\n' +
        '                    <el-option v-for="item in siteValue" :key="item.id" :label="item.siteName"\n' +
        '                               :value="item.id">\n' +
        '                    </el-option>\n' +
        '                </el-select>',
    created: function () {
        //获取后台数据
        this.$http.get('/readMap/getsitevalueinsql.do',{emulateJSON:true}).then(function (res){
            this.siteValue = res.data;
            this.siteOptionValue = res.data[0].id;
            this.$emit('send-property-hide-first', res.data[0]);
        })
    },methods:{
        changFunction(id){//change事件
            let entity = {};
            entity = this.siteValue.find((item)=>{
                return item.id === id;  //筛选出匹配数据，这里的value是你遍历数组每一项的value，如果没有对后台返回的数据做处理，一般为id
            });
            //返回一个值
            this.$emit('send-property-hide',  entity);
        }
    }
});
